package com.tanhua.manager;

import com.tanhua.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/manage")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping(name = "用户登出",value = "/users/{userID}")
    public ResponseEntity findByUid(@PathVariable("userID") Long userId) throws Exception {

        return userService.findByUid(userId);
    }


    @GetMapping(name = "用户信息的分页查询展示",value = "/users")
    public ResponseEntity users(Integer page,Integer pagesize) throws Exception {
        return userService.findUsers(page,pagesize);
    }


    @GetMapping(name = "分页展示用户的小视频",value = "/videos")
    public ResponseEntity findByvideos(Integer page,Integer pagesize,Long uid) throws Exception {

        return userService.findByvideos(page,pagesize,uid);
    }


    @GetMapping(name = "分页展示用户的动态或审核状态的动态",value = "/messages")
    public ResponseEntity messages(Integer page,Integer pagesize,Long uid,Integer state) throws Exception {

        return userService.messages(page,pagesize,uid,state);
    }


    @GetMapping(name = "单条动态详情展示",value = "/messages/{id}")
    public ResponseEntity findByPublishId(@PathVariable("id") String id) throws Exception {

        return userService.findByPublishId(id);
    }



    @GetMapping(name = "单条动态详情展示",value = "/messages/comments")
    public ResponseEntity findByComments(Integer page,Integer pagesize,String messageID) throws Exception {

        return userService.findByComments(page,pagesize,messageID);
    }

    @PostMapping(value = "/users/freeze",name = "用户冻结")
    public ResponseEntity freeze(@RequestBody Map map){
        Integer userId =(Integer) map.get("userId");
        Integer freezingTime =Integer.parseInt((String) map.get("freezingTime"));
        Integer freezingRange =Integer.parseInt((String) map.get("freezingRange"));

        return userService.freeze(userId,freezingTime,freezingRange);
    }




    @PostMapping(value = "/users/unfreeze",name = "解除用户冻结")
    public ResponseEntity unfreeze(@RequestBody Map map){
        Integer userId =(Integer) map.get("userId");
        String reasonsForThawing =(String) map.get("reasonsForThawing");
        return userService.unfreeze(userId,reasonsForThawing);
    }






}
